#include <boost/algorithm/string.hpp>
#include "HttpClient.h"

const string CHttpClient::http_scheme = "http://";

CHttpClient::CHttpClient()
{

}

CHttpClient::~CHttpClient()
{

}

bool CHttpClient::Get(const string &url, CHttpResponse &response)
{
    return true;
}

void CHttpClient::SplitUrl(const string &url, string &domain,
                                  string &port, string &path)
{
    string url_scheme = url.substr(0, http_scheme.length());
    to_lower(url_scheme);
    size_t domain_begin = 0;
    if (url_scheme == http_scheme)
    {
        domain_begin = http_scheme.length(); 
    }
    
    size_t pos_slash = url.find('/', domain_begin);
    if (pos_slash == string::npos)
    {
        path.clear();
        pos_slash = url.length();
    }
    else
    {
        path = url.substr(pos_slash);
    }

    size_t pos_colon = url.rfind(':', pos_slash - 1);
    if (pos_colon == string::npos)
    {
        port.clear();
        domain = url.substr(domain_begin, pos_slash - domain_begin);
    }
    else
    {
        port = url.substr(pos_colon + 1, pos_slash - pos_colon - 1);
        domain = url.substr(domain_begin, pos_colon - domain_begin);
    }
}

void CHttpClient::Conncet(tcp::socket &socket, const string &domain, const string &port)
{
}

void CHttpClient::Send(tcp::socket &socket, const string& data)
{
}

void CHttpClient::Recv(tcp::socket &socket, string& data)
{
}

